﻿package mortal.game.view.copy.wine.view
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.component.windowTip.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.wine.renderer.*;
    import mortal.game.view.copy.wine.util.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class WinePartyMainWin extends BaseWindow
    {
        private var _juniorItemList:GTileList;
        private var _middleItemList:GTileList;
        private var _seniorItemList:GTileList;
        private var _currFunds:GTextFiled;
        private var _checkDetailLink:GTextFiled;
        private var _openWinePartyBtn:GLoadingButton;
        private var _enterWinePartyBtn:GLoadingButton;
        private var _desc:GTextFiled;
        private var _goldIcon:GBitmap;
        private var _numInput:GNumericStepper;
        private var _donateBtn:GButton;
        private var _tipInfo:GTextFiled;
        private var _selectBg:GImageBitmap;

        public function WinePartyMainWin(param1:ILayer = null)
        {
            super(param1);
            setSize(738 + 3, 495);
            title = Language.getString(41004);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(7, 39, 726 + 3, 496 + 40 - 164 + 34, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WineJunior, 17, 39 + 131 + 40 - 164, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WineMiddle, 17 + 238, 39 + 131 + 40 - 164, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WineSenior, 17 + 238 * 2, 39 + 131 + 40 - 164, this));
            this._selectBg = UIFactory.gImageBitmap(ImagesConst.WinePartySelectBorder, 17 + 238 * 2, 39 + 131 + 40 - 164, this);
            this._juniorItemList = UIFactory.tileList(7 + 64 + 23, 39 + 211 + 40 - 164 - 14, 147, 42, this);
            this._juniorItemList.columnWidth = 46;
            this._juniorItemList.rowHeight = 41;
            this._juniorItemList.horizontalGap = 0;
            this._juniorItemList.verticalGap = 0;
            this._juniorItemList.setStyle("skin", new Bitmap());
            this._juniorItemList.setStyle("cellRenderer", WinePreviewItemCellRenderer);
            this._middleItemList = UIFactory.tileList(7 + 300 + 23, 39 + 211 + 40 - 164 - 14, 147, 42, this);
            this._middleItemList.columnWidth = 46;
            this._middleItemList.rowHeight = 41;
            this._middleItemList.horizontalGap = 0;
            this._middleItemList.verticalGap = 0;
            this._middleItemList.setStyle("skin", new Bitmap());
            this._middleItemList.setStyle("cellRenderer", WinePreviewItemCellRenderer);
            this._seniorItemList = UIFactory.tileList(7 + 539 + 23, 39 + 211 + 40 - 164 - 14, 147, 42, this);
            this._seniorItemList.columnWidth = 46;
            this._seniorItemList.rowHeight = 41;
            this._seniorItemList.horizontalGap = 0;
            this._seniorItemList.verticalGap = 0;
            this._seniorItemList.setStyle("skin", new Bitmap());
            this._seniorItemList.setStyle("cellRenderer", WinePreviewItemCellRenderer);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.WineBottomInfo, 10 + 2, 369 - 2, this));
            this._currFunds = UIFactory.gTextField("", 7 + 119 + 85, 39 + 457 - 5 + 40 - 164 + 14, 157, 25, this, GlobalStyle.textFormatHuang2.setSize(17));
            this._goldIcon = UIFactory.gBitmap(ImagesConst.Yuanbao, 0, this._currFunds.y + 2, this);
            this._numInput = UIFactory.gNumericStepper(481, 382, 50, 20, this, 99, 1, "NumericStepper", GlobalStyle.textFormatChen.center(), GNumericStepper.SetMaxNum);
            this._numInput.value = 1;
            this._numInput.configEventListener(Event.CHANGE, this.changeNum);
            this._numInput.maximum = 1000;
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.Yuanbao, 534 + 18, (this._currFunds.y + 1), this));
            this._donateBtn = UIFactory.gButton(Language.getString(41005), 562 + 18, 380, 58, 24, this);
            this._donateBtn.configEventListener(MouseEvent.CLICK, this.onDonateHandler);
            this._tipInfo = UIFactory.gTextField(Language.getString(41006), 72, 414 - 2, 250, 25, this, GlobalStyle.textFormatLv.setSize(13));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41007), 387 - 2, 414 - 2, 212, 25, this, GlobalStyle.textFormatLv.setSize(13)));
            this._checkDetailLink = UIFactory.gTextField("", 7 + 41 + 503 + 30 + 6, 414 - 2, 157, 25, this, GlobalStyle.textFormatLv.setSize(12));
            this._checkDetailLink.htmlText = HTMLUtil.addLink(Language.getString(41008), GlobalStyle.colorLv);
            this._checkDetailLink.configEventListener(TextEvent.LINK, this.onLinkHandler);
            this._checkDetailLink.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._checkDetailLink.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._desc = UIFactory.gTextField("", 648 + 20 + 4, 414 - 2, 60, 25, this, GlobalStyle.textFormatLv.setSize(12));
            this._desc.htmlText = HTMLUtil.addLink(Language.getString(41009), GlobalStyle.colorLv);
            this._desc.configEventListener(MouseEvent.CLICK, this.onLinkClickHandler);
            this._desc.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._desc.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._openWinePartyBtn = UIFactory.gLoadingButton(ResFileConst.OpenWineBtn, 7 + 397 - 18 - 112 + 20, 39 + 455 - 3 + 40 - 164 + 82 + 3, 157, 39, this);
            this._openWinePartyBtn.configEventListener(MouseEvent.CLICK, this.onOpenWinePartyHandler);
            this._enterWinePartyBtn = UIFactory.gLoadingButton(ResFileConst.EnterWinePartyBtn, 7 + 397 - 18 - 112 + 20, 39 + 455 - 3 + 40 - 164 + 82 + 3, 157, 39, this);
            this._enterWinePartyBtn.configEventListener(MouseEvent.CLICK, this.onEnterWinePartyHandler);
            this.initItemList();
            this.initBtnState();
            this.initWineFunds();
            this.addListener();
            return;
        }// end function

        private function addListener() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.GUILD_INFO_UPDATE, this.onTotalFundsUpdate);
            Dispatcher.addEventListener(EventName.WinePartyBtnStateUpdate, this.onBtnStateUpdate);
            return;
        }// end function

        private function removeListener() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.GUILD_INFO_UPDATE, this.onTotalFundsUpdate);
            Dispatcher.removeEventListener(EventName.WinePartyBtnStateUpdate, this.onBtnStateUpdate);
            return;
        }// end function

        private function initItemList() : void
        {
            var _loc_7:String = null;
            var _loc_1:* = GuildWinePartyCopyConfig.instance.getInfoByLevel(1).rewardShow;
            var _loc_2:* = GuildWinePartyCopyConfig.instance.getInfoByLevel(2).rewardShow;
            var _loc_3:* = GuildWinePartyCopyConfig.instance.getInfoByLevel(3).rewardShow;
            var _loc_4:* = new DataProvider();
            var _loc_5:* = new DataProvider();
            var _loc_6:* = new DataProvider();
            if (_loc_1)
            {
                for each (_loc_7 in _loc_1.split("#"))
                {
                    
                    _loc_4.addItem(new ItemData(int(_loc_7)));
                }
                this._juniorItemList.dataProvider = _loc_4;
                this._juniorItemList.drawNow();
            }
            if (_loc_2)
            {
                for each (_loc_7 in _loc_2.split("#"))
                {
                    
                    _loc_5.addItem(new ItemData(int(_loc_7)));
                }
                this._middleItemList.dataProvider = _loc_5;
                this._middleItemList.drawNow();
            }
            if (_loc_3)
            {
                for each (_loc_7 in _loc_3.split("#"))
                {
                    
                    _loc_6.addItem(new ItemData(int(_loc_7)));
                }
                this._seniorItemList.dataProvider = _loc_6;
                this._seniorItemList.drawNow();
            }
            return;
        }// end function

        private function initBtnState() : void
        {
            if (WinePartyUtil.isLeaderOrDeputyLeader())
            {
                if (GameController.copy.winePartyCopy.isWinePartyOpen)
                {
                    this._openWinePartyBtn.visible = false;
                    this._enterWinePartyBtn.visible = true;
                }
                else
                {
                    this._openWinePartyBtn.visible = true;
                    this._enterWinePartyBtn.visible = false;
                }
            }
            else
            {
                this._openWinePartyBtn.visible = false;
                this._enterWinePartyBtn.visible = true;
            }
            return;
        }// end function

        private function initWineFunds() : void
        {
            this.onTotalFundsUpdate();
            return;
        }// end function

        private function onDonateHandler(event:MouseEvent) : void
        {
            if (Cache.instance.role.money.gold < this._numInput.value)
            {
                MsgManager.showRollTipsMsg(Language.getString(41010));
                return;
            }
            if (Cache.instance.guild.selfGuildInfo.baseInfo.money >= WinePartyConst.Wine_Donate_MaxValue)
            {
                MsgManager.showRollTipsMsg(Language.getString(41011));
                return;
            }
            var _loc_2:* = new Dictionary();
            _loc_2[EPriceUnit._EPriceUnitGold] = this._numInput.value;
            var _loc_3:* = new SPlayerItem();
            GameProxy.guild.donateResource(_loc_3, _loc_2);
            return;
        }// end function

        private function onOpenWinePartyHandler(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (WinePartyUtil.isInWinePartyTime())
            {
                _loc_2 = Cache.instance.guild.selfGuildInfo.baseInfo.money;
                if (_loc_2 >= 0 && _loc_2 < 300)
                {
                    _loc_2 = 0;
                }
                else if (_loc_2 >= 300 && _loc_2 < 1000)
                {
                    _loc_2 = 300;
                }
                else
                {
                    _loc_2 = 1000;
                }
                _loc_3 = GuildWinePartyCopyConfig.instance.getWineCopyLevelByCost(_loc_2);
                Cache.instance.copy.wineParty.currWinePartyLevel = _loc_3;
                GameProxy.guild.openGuildWinePartyCopy(_loc_3);
            }
            return;
        }// end function

        private function onEnterWinePartyHandler(event:MouseEvent) : void
        {
            if (WinePartyUtil.isInWinePartyTime())
            {
                if (!GameController.copy.winePartyCopy.isWinePartyOpen)
                {
                    MsgManager.showRollTipsMsg(Language.getString(41012));
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.WinePartyEnterCopy));
            }
            return;
        }// end function

        private function onLinkHandler(event:TextEvent) : void
        {
            WinePartyDonateRankWin.instance.show();
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        private function onTotalFundsUpdate(param1:Object = null) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:String = null;
            if (Cache.instance.guild.selfGuildInfo && Cache.instance.guild.selfGuildInfo.baseInfo)
            {
                _loc_2 = Cache.instance.guild.selfGuildInfo.baseInfo.money;
                this._currFunds.text = _loc_2 + "";
                this._goldIcon.x = this._currFunds.x + this._currFunds.textWidth + 9;
                if (_loc_2 >= 0 && _loc_2 < 300)
                {
                    _loc_3 = 1;
                    _loc_4 = Language.getString(41013);
                    this._selectBg.x = 17;
                }
                else if (_loc_2 >= 300 && _loc_2 < 1000)
                {
                    _loc_3 = 2;
                    _loc_4 = Language.getString(41014);
                    this._selectBg.x = 17 + 238;
                }
                else if (_loc_2 >= 1000)
                {
                    _loc_3 = 3;
                    _loc_4 = Language.getString(41015);
                    this._selectBg.x = 17 + 238 * 2;
                }
                this._tipInfo.htmlText = Language.getStringByParam(41016, _loc_3, _loc_4);
            }
            return;
        }// end function

        private function onBtnStateUpdate(event:DataEvent) : void
        {
            if (GameController.copy.winePartyCopy.isWinePartyOpen)
            {
                this._openWinePartyBtn.visible = false;
                this._enterWinePartyBtn.visible = true;
            }
            else
            {
                this.initBtnState();
            }
            return;
        }// end function

        private function onLinkClickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = new WindowTipData();
            _loc_2.type = WindowTipType.WineParty_Explain;
            var _loc_3:* = Language.getString(40701) + Language.getString(40702) + Language.getString(40703) + Language.getString(40704) + Language.getString(40705) + Language.getString(40706) + Language.getString(40707);
            _loc_2.tip = _loc_3;
            _loc_2.title = Language.getString(41017);
            _loc_2.tipW = 500;
            _loc_2.tipH = 500;
            WindowTipManager.showTip(_loc_2);
            return;
        }// end function

        protected function changeNum(event:Event = null) : void
        {
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._openWinePartyBtn.dispose();
            this._currFunds.dispose();
            this._checkDetailLink.dispose();
            this._juniorItemList.dispose();
            this._middleItemList.dispose();
            this._seniorItemList.dispose();
            this._enterWinePartyBtn.dispose();
            this._desc.dispose();
            this._goldIcon.dispose();
            this._numInput.dispose();
            this._donateBtn.dispose();
            this._tipInfo.dispose();
            this._selectBg.dispose();
            this._openWinePartyBtn = null;
            this._currFunds = null;
            this._checkDetailLink = null;
            this._juniorItemList = null;
            this._middleItemList = null;
            this._seniorItemList = null;
            this._enterWinePartyBtn = null;
            this._desc = null;
            this._goldIcon = null;
            this._numInput = null;
            this._donateBtn = null;
            this._tipInfo = null;
            this._selectBg = null;
            this.removeListener();
            return;
        }// end function

    }
}
